﻿DECLARE @i int=1,@Date varchar(10)='2020-05-01',@EndDate varchar(10)='2020-12-31'
WHILE(@Date<=@EndDate)
BEGIN
	PRINT @Date
  
  INSERT INTO bd_sys_dim_date(date_key,date,date_year,date_month, date_day, date_week, date_week_name)
  select CAST(CONVERT(VARCHAR(24),CAST(@Date AS DATE),112) AS INT),@Date,YEAR(@Date) ,MONTH(@Date),DAY(@Date),CASE datepart(weekday,@Date) WHEN 1 THEN 7 ELSE datepart(weekday,@Date)-1 END, datename(weekday,@Date)

	SET @Date=CONVERT(varchar(10),DATEADD(DAY,1,@Date),120) 
END



DECLARE @i int=1,@Date varchar(10)='2019-12-01',@EndDate varchar(10)='2019-12-31'
    SELECT CONVERT(VARCHAR(24),CAST(@Date AS DATE),112),@Date,YEAR(@Date) ,MONTH(@Date),DAY(@Date),datepart(weekday,@Date), datename(weekday,@Date),
        CASE datepart(weekday,@Date) WHEN 1 THEN 7 ELSE datepart(weekday,@Date)-1 END

  TRUNCATE TABLE bd_sys_dim_date

SELECT * FROM bd_sys_dim_date

SELECT CONVERT(VARCHAR(24),GETDATE(),112)